<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="90px">
      <el-form-item label="客户姓名：" prop="clientName">
        <el-input v-model="queryParams.customName" placeholder="客户姓名" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号码：" prop="clientPhone">
        <el-input v-model="queryParams.customPhoneNum" placeholder="客户手机号码" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证号：" prop="clientID">
        <el-input v-model="queryParams.customIdNum" placeholder="客户身份证号" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="渠道名称：" prop="channel">
        <el-input v-model="queryParams.channel" placeholder="渠道名称" clearable style="width: 300px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="申请时间：">
        <el-date-picker v-model="dateRange" style="width: 300px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item>
      <el-form-item>
        <div style="margin-right: 50px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermi="['system:post:export']" type="warning" plain icon="el-icon-download" size="mini"
          @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>
    <!-- data=你后台查出的数据 -->
    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" />
      <el-table-column label="产品名称" align="center" prop="loanInfo[0].productionInfo.productionName" />
      <el-table-column label="客户姓名" align="center" prop="clientName" />
      <el-table-column label="渠道" align="center" prop="loanInfo[0].productionInfo.channelInfo.linkman" />
      <el-table-column label="资方名称" align="center" prop="loanInfo[0].productionInfo.channelInfo.channelName" />
      <el-table-column label="申请金额" align="center" prop="loanInfo[0].loanAmount" />
      <el-table-column label="期数" align="center" prop="loanInfo[0].periods.periods" />
      <el-table-column label="累计放款" align="center" prop="loanInfo[0].loansTotal" />
      <el-table-column label="提交时间" align="center" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loanInfo[0].applicantTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请次数" align="center" prop="loanInfo[0].applicantNum" />
      <el-table-column label="申请状态" align="center" prop="loanInfo[0].applicantStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.loan_info_applicant_status" :value="scope.row.loanInfo[0].applicantStatus" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermi="['system:post:edit']" size="mini" type="text" icon="el-icon-more"
            @click="handleDetail(scope.row)">终审</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
// 导入api
import { listAllApplicant, searchClientProduction } from '../../../api/finalTrial'
export default {
  // 字典导入
  dicts: ['order_status', 'source_status', 'loan_info_applicant_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      dataList: [],
      restColoums: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

        customName: undefined,
        customPhoneNum: undefined,
        customIdNum: undefined,

        channel: undefined,
      },
      // 表单参数
      form: {},
      data:{
        ids:this.ids
      }
    }
  },
  created() {
    this.getList()
  },
  watch: {
    dataList(newVal) {
      for (let item in newVal) {
        this.restColoums.push(newVal[item].loanInfo);
      }
    },
    ids(newVal) {
      this.data.ids = newVal;
    }
  },
  methods: {
    getList() {
      this.loading = true
      listAllApplicant(this.queryParams.pageNum, this.queryParams.pageSize).then(response => {
        console.log(response)
        this.dataList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getDataList() {
      console.log(this.ids)
      console.log("data",this.data)
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleQuery() {
      console.log(this.addDateRange(this.queryParams, this.dateRange))
      searchClientProduction(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
        console.log(res)
        if (res.code == 200) {
            this.loading = true
            this.dataList = res.data
            this.loading = false
          } else {
            this.$notify({
              message: res.msg,
              type: 'success'
            });
          }
      }).catch();
    },
    // 查看进件详情
    handleDetail(row) {
      console.log(row);
      const clientId = row.id;
      this.$router.push("/finalTrialDetail/index/" + clientId);
    },

    reset() {
      this.form = {
        code: 1,
        status: '0'
      }
      this.resetForm('form')
    },
    handleExport() {
      console.log(this.exportParams)
      this.download('finalTrial/exportChosen', this.data, `终审信息列表_${new Date().getTime()}.xlsx`)
    },
    handleUpdate(row) {
      const feedId = row.id;
      this.$router.push("/holyShit/fuck/" + feedId);
    },

    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.loanInfo[0].loanInfoId);
      this.single = selection.length !== 1
      this.multiple = !selection.length
    }
  }

}

</script>

